namespace Atlantis
{
    public class DocumentView : GLib.Object, IDocumentView, IWidgetProvider, ISmartPartInfoProvider
    {
        private Gtk.ScrolledWindow scrolledWindow;
        private Gtk.SourceView sourceView;
        private Document document;

        public DocumentView()
        {
			// test
            //base(null,null);
        }
        
        public Document Document
        {
			get
			{
				return this.document;
			}
		}

        public ISmartPartInfo GetSmartPartInfo()
        {
            stderr.printf("GetSmartPartInfo()");
            var ret = new SmartPartInfo();
            if (document != null)
            {
               ret.Label = document.Name;
            }
            else
            {
                ret.Label = "null";
            }
            return ret;
        }

        construct
        {
            this.scrolledWindow = new Gtk.ScrolledWindow(null,null);
            this.sourceView = new Gtk.SourceView();
                        
            scrolledWindow.add(sourceView);
            scrolledWindow.show_all();
        }

        public void Load(Document document)
        {
            stderr.printf("documentview.Load(Document document)");
            this.document = document;
            if (this.sourceView != null)
            {
                stderr.printf(" this.sourceView.set_buffer(document);");
                this.sourceView.set_buffer(document);
            }
            
            modify_font();
        }
        
        private void modify_font()
        {
			string font_family = "Mono";
			int font_size = 10;
			var font_description = new Pango.FontDescription();
			
			font_description.set_family(font_family);
			font_description.set_size((int)(font_size * Pango.SCALE));
			
			sourceView.modify_font( font_description );
		}

        public Gtk.Widget Widget
        {
            get
            {
                stderr.printf("DocumentView.Widget");
                return this.scrolledWindow;
            }
        }
    }
}
